import re
import requests
import os
src = "https://www.sanchuangedu.cn"
# 获取网页源代码
ret = requests.get(src)
msg = ret.text
# 得到图片网址
pc_list = re.findall(r'(?:<img.*src=")(.*\.jpg|.*\.png|.*\.gif)(?:")',msg)
# 判断文件夹是否存在；若不存在则创建文件夹
os.makedirs("D:\\图片")
# 下载图片到本地
for i in pc_list:
    name = re.findall(r"(?:.*/)(.*\.jpg|.*\.png|.*\.gif)",i)
    with open(f"D:\\图片\\{name[0]}","wb+") as f:
        f.write(requests.get(src+i).content)
print("下载完成!")